<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>常熟理工问卷系统</title>
    <link rel="stylesheet" th:href="@{/asserts/bootstrap4/css/bootstrap.css}">
    <link rel="stylesheet" th:href="@{/asserts/css/TeacherSystem.css}">
</head>
<body>
    <div th:replace="Default::topNav(${username},${account})"></div>
    <div th:replace="Default::leftNav('MyQuestion',${userType})"></div>
    <div class="container-fluid">
        <div class="myQuestions" th:if="${questionStateList}">
            <div class="oneQuestion" th:each="questionState : ${questionStateList}">
                <div class="QuestionId" title="问卷标号可以拼入链接中访问">
                    <span>#id:</span>
                    <span id="oneQuestion_id" th:text="${questionState.question.id}"></span>
                </div>
                <div class="QuestionTitle" title="问卷标题" th:switch="${questionState.state}">
                    <span th:text="${questionState.question.title}"></span>
                    <span th:case="9" style="color: red">(审核驳回)</span>
                    <span th:case="8" style="color: red">(草稿)</span>
                    <span th:case="0" style="color: deepskyblue">(正在审核中)</span>
                    <span th:case="1" style="color: green">(正在进行中)</span>
                    <span th:case="2" style="color: gold">(通过审核,未到开始时间)</span>
                    <span th:case="3" style="color: gray">(已经结束)</span>
                </div>
                <div class="QuestionEdit" th:switch="${questionState.state}">
                    <!--审核驳回-->
                    <div th:case="9">
                        <a class="btn btn-primary" style="color: white" th:href="@{'/'+${userType}+'EditQuestion/'+${questionState.question.id+''}}">修改</a>
                        <img class="QuestionDel" th:src="@{asserts/img/delete.png}">
                    </div>

                    <!--草稿-->
                    <div th:case="8">
                        <a class="btn btn-primary" style="color: white" th:href="@{'/'+${userType}+'EditQuestion/'+${questionState.question.id+''}}">编辑</a>
                        <img class="QuestionDel" th:src="@{asserts/img/delete.png}">
                    </div>

                    <!--正在审核中-->
                    <div th:case="0">
                        <a class="btn btn-dark" style="color: white"
                           th:href="@{'/PreViewQuestionForm/'+${questionState.question.id+''}}" target="_blank">预览</a>
                        <img class="QuestionDel" th:src="@{asserts/img/delete.png}">
                    </div>

                    <!--正在进行中-->
                    <div th:case="1">
                        <a class="btn btn-primary" style="color: white"
                           th:href="@{'/QuestionForm/'+${questionState.question.id+''}}" target="_blank">前往填写地址</a>
                        <a class="btn btn-dark" style="color: white"
                           th:href="@{'/'+${userType}+'CheckForm/'+${questionState.question.id+''}+'?page=1'}">查看表单</a>
                        <a class="btn btn-info" style="color: white"
                           th:href="@{'/ComputeForm/'+${questionState.question.id+''}}" target="_blank">表单统计</a>
                        <img class="QuestionDel" th:src="@{asserts/img/delete.png}">
                    </div>

                    <!--通过审核,未到开始时间-->
                    <div th:case="2">
                        <a class="btn btn-primary" style="color: white"
                           th:href="@{'/PreViewQuestionForm/'+${questionState.question.id+''}}" target="_blank">预览</a>
                        <img class="QuestionDel" th:src="@{asserts/img/delete.png}">
                    </div>

                    <!--结束-->
                    <div th:case="3">
                        <a class="btn btn-primary" style="color: white"
                           th:href="@{'/PreViewQuestionForm/'+${questionState.question.id+''}}" target="_blank">预览</a>
                        <a class="btn btn-dark" style="color: white"
                           th:href="@{'/'+${userType}+'CheckForm/'+${questionState.question.id+''}+'?page=1'}">查看填写</a>
                        <a class="btn btn-info" style="color: white"
                           th:href="@{'/ComputeForm/'+${questionState.question.id+''}}" target="_blank">表单统计</a>
                        <img class="QuestionDel" th:src="@{asserts/img/delete.png}">
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="noQuestions" th:if="not ${questionStateList}">
            <img th:src="@{asserts/img/noquestion.png}">
            <div>你还没有发布一个问卷哦~ 快去发布吧！</div>
        </div>
    </div>
</body>
<script th:src="@{/asserts/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{/asserts/js/popper.min.js}"></script>
<script th:src="@{/asserts/bootstrap4/js/bootstrap.js}"></script>
<script th:src="@{/asserts/js/canvas-nest.min.js}"></script>
<script th:replace="Default :: linklist(${userType})"></script>
<script th:if="${userType} eq 'Teacher'">
    $("#AuditForm").click(function () {
       window.location.href = "/TeacherAuditForm?page=1";
    });
</script>
<script type="text/javascript" th:inline="javascript">
    $(".QuestionDel").click(function () {
        var delid = $(this).parents(".oneQuestion").find("#oneQuestion_id").text();
        $.ajax({
            type:"POST",
            url:[[${"/"+userType+"Home/delete"}]],
            contentType:"application/json",
            dataType:"json",
            data:JSON.stringify({
                deleteid:delid
            }),
            beforeSend(XMLHttpRequest){
                console.log(delid);
                return confirm("此操作会连带填写的表单一起删除，确定继续吗?");
            },
            success:function (data) {
                if (data.code === 200){
                    alert("删除成功！");
                    window.location.href = [[${"/"+userType+"Home?page=1"}]];
                }else{
                    alert(data.msg);
                }
            },
            error:function (err) {
                alert(err.toString());
            }
        })
    });
</script>
</html>